import React from 'react'
import PropTypes from 'prop-types'
import {Modal, Table} from 'antd'
import classnames from 'classnames'
import {DropOption} from 'components'
import AnimTableBody from 'components/DataTable/AnimTableBody'
import styles from './List.less'
import moment from 'moment'

const {confirm} = Modal

const List = ({
                onDeleteItem, onEditItem, isMotion, location, ...tableProps
              }) => {

  const handleMenuClick = (record, e) => {
    if (e.key === 'edit') {
      onEditItem(record)
    } else if (e.key === 'delete') {
      confirm({
        title: '您确定要删除这条数据吗?',
        okText: '确定',
        cancelText: '取消',
        onOk () {
          onDeleteItem(record.id)
        },
      })
    }
  }

  const columns = [
    {
      title: '登陆IP',
      dataIndex: 'ip',
      key: 'ip',
      width: 100,
    }, {
      title: '操作时间',
      dataIndex: 'operatorTime',
      key: 'operatorTime',
      width: 100,
      render: ctime => moment(ctime).format('YYYY-MM-DD hh:mm:ss'),
    }, {
      title: '操作内容',
      dataIndex: 'operateContent',
      key: 'operateContent',
      width: 100,
    }, {
      title: '操作人',
      dataIndex: 'operatorName',
      key: 'operatorName',
      width: 100,
    },
  ]

  const AnimateBody = (props) => {
    return <AnimTableBody {...props} />
  }

  const CommonBody = (props) => {
    return <tbody {...props} />
  }

  return (
    <Table
      {...tableProps}
      className={classnames(styles.table)}
      scroll={{x: 800}}
      columns={columns}
      simple
      rowKey={record => record.id}
      components={{
        body: {wrapper: isMotion ? AnimateBody : CommonBody},
      }}
    />
  )
}

List.propTypes = {
  onDeleteItem: PropTypes.func,
  onEditItem: PropTypes.func,
  location: PropTypes.object,
}

export default List
